﻿
namespace ZR.Model.Models.ProductionControl
{
    /// <summary>
    /// 异常任务
    /// </summary>
    [SugarTable("cks_packaging_exception_task")]
    [Table(Name = "cks_packaging_exception_task")]
    public class CksPackagingExceptionTask : BaseEntity
    {
        public CksPackagingExceptionTask()
        {
           
            this.Guid = System.Guid.NewGuid().ToString("N");
        }

        //public CksPackagingExceptionTask() { 
            
        //}
        [Column(IsIgnore =true)]
        [SugarColumn(IsIgnore =true)]
        public string Guid {  get; set; }

        /// <summary>
        /// Id 
        /// </summary>
        [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
        [Column(IsPrimary = true, IsIdentity = true)]
        public long Id { get; set; }

        /// <summary>
        /// 任务编号 
        /// </summary>
        public string TaskNo { get; set; } = string.Empty;

        /// <summary>
        /// 流转容器编号 
        /// </summary>
        public string ContainerNo { get; set; } = string.Empty;

        /// <summary>
        /// 面单号 
        /// </summary>
        public string WaybillNo { get; set; } = string.Empty;

        /// <summary>
        /// 订单号 
        /// </summary>
        public string OrderNo { get; set; } = string.Empty;

        /// <summary>
        /// 包裹号 
        /// </summary>
        public string PackageNo { get; set; }

        /// <summary>
        /// 异常消息 
        /// </summary>
        [Column(IsIgnore = true)]
        [SugarColumn(IsIgnore =true)]
        public string Message
        {
            get {
                return GetNgMessage();
            }
        }

        /// <summary>
        /// 异常类型 
        /// </summary>
        [Column(MapType = typeof(int))]
        public PackageNgType NgType { get; set; }

        /// <summary>
        /// 禁用(无效)状态 
        /// </summary>
        public bool Nullity { get; set; }

        /// <summary>
        /// 生产模式 1正式 2调试
        /// </summary>
        public int ProductMode { get; set; }
        /// <summary>
        /// 报警位置
        /// </summary>
        public string Location { get; set; } = string.Empty;
        /// <summary>
        /// 创建时间 
        /// </summary>
        public DateTime CreatedTime { get; set; } = DateTime.Now;

        public string GetNgMessage()
        {
            return NgType switch
            {
                PackageNgType.长度不符合 => $"1-长度不符合",
                PackageNgType.宽度不符合 => $"2-宽度不符合",
                PackageNgType.高度不符合 => $"3-高度不符合",
                PackageNgType.扫码NG => $"4-{Location}-扫码NG",
                PackageNgType.订单箱号重复 => $"5-订单箱号重复",
                PackageNgType.无订单信息 => $"6-{Location}-无订单信息",
                PackageNgType.校验失败 => $"7-{Location}-校验失败",
                _ => "未知错误"
            };
        }
        

    }

    public enum PackageNgType:int
    {
        长度不符合 = 1,
        宽度不符合 = 2,
        高度不符合 = 3,
        扫码NG = 4,
        订单箱号重复 = 5,
        无订单信息 = 6,
        校验失败 = 7
    }

    public enum LocationEype:int
    {

    }

}